import React, { useEffect, useState } from "react";
import { useParams, useLocation, Navigate, useNavigate } from "react-router-dom";
import { Descriptions, Card, Button } from "antd";
import { hospitalDetailType } from "@api/hospital/model/hospitalListTypes";
import { getHospitalDetailRequest } from "@/api/hospital/hospitalList";
export default function HospitalShow() {
  const { id } = useParams();
  const navigate=useNavigate()
  const [hospitalDetail, setHospitalDetail] = useState<hospitalDetailType>({});

  //进入医院详情页面就请求数据
  useEffect(() => {
    const getHosDetail = async () => {
      const result = await getHospitalDetailRequest(id as string);
      // console.log(result);
      //将数据用变量保存
      setHospitalDetail(result);
    };
    getHosDetail();
  }, []);

  return (
    <div>
      <Card>
        <Descriptions title="基本信息" bordered column={2}>
          <Descriptions.Item label="医院名称">
            {hospitalDetail.hospital?.hosname}
          </Descriptions.Item>
          <Descriptions.Item label="医院Logo">
            {hospitalDetail.hospital?.logoData ? (
              <img
                width={200}
                src={`data:image/jpeg;base64,${hospitalDetail.hospital?.logoData}`}
                alt="医院Logo"
              />
            ) : (
              ""
            )}
          </Descriptions.Item>
          <Descriptions.Item label="医院编码">
            {hospitalDetail.hospital?.hoscode}
          </Descriptions.Item>
          <Descriptions.Item label="医院地址">
            {hospitalDetail.hospital?.address}
          </Descriptions.Item>
          <Descriptions.Item label="医院坐车路线" span={2}>
            {hospitalDetail.hospital?.route}
          </Descriptions.Item>
          <Descriptions.Item label="医院简介" span={2}>
            {hospitalDetail.hospital?.intro}
          </Descriptions.Item>
        </Descriptions>

        <Descriptions
          title="预约规则信息"
          bordered
          column={2}
          style={{ marginTop: 30 }}
        >
          <Descriptions.Item label="预约周期">
            {hospitalDetail.bookingRule?.cycle}
          </Descriptions.Item>
          <Descriptions.Item label="放号时间">
            {hospitalDetail.bookingRule?.releaseTime}
          </Descriptions.Item>
          <Descriptions.Item label="停挂时间">
            {hospitalDetail.bookingRule?.quitTime}
          </Descriptions.Item>
          <Descriptions.Item label="停号时间">
            {hospitalDetail.bookingRule?.stopTime}
          </Descriptions.Item>
          <Descriptions.Item label="预约规则" span={2}>
            {hospitalDetail.bookingRule?.rule.map((item, index) => {
              return <p key={index}>{item}</p>;
            })}
          </Descriptions.Item>
        </Descriptions>

        <Button style={{ marginTop: 30 }} onClick={() => {navigate(-1)}}>
          返回
        </Button>
      </Card>
    </div>
  );
}
